<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" import="net.sf.json.*"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><s:text name="title"/></title>
<link href="<%=request.getContextPath()%>/stage/css/inside.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/stage/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/stage/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/stage/js/json2.js"></script>
<script type="text/JavaScript">
<!--
var items;
var total=0;
Date.prototype.format = function(format)
{
        var o = 
        {
            "M+" : this.getMonth()+1, //month
            "d+" : this.getDate(),    //day
            "h+" : this.getHours(),   //hour
            "m+" : this.getMinutes(), //minute
            "s+" : this.getSeconds(), //second
            "q+" : Math.floor((this.getMonth()+3)/3), //quarter
            "S" : this.getMilliseconds() //millisecond
        }
        
        if(/(y+)/.test(format)) 
        format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
        if(new RegExp("("+ k +")").test(format))
        format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
        return format;
}
$(document).ready(function() {
	var d = new Date();
	$("#orderDate").val(d.format('yyyy-MM-dd'));
	var str='<%=JSONArray.fromObject(request.getAttribute("dataList")).toString()%>';
	if(str.length>10)items=JSON.parse(str);
	setTable(items);
})
function del(index){
	items.splice(index,1);
	setTable(items);
}
function saveOrder(){
	if(items==null||items.length<=0){alert("商品为空，请加入商品.");return false;}
	var r=confirm("确认是否提交订单.");
	if (r==true){
		var server="<%=request.getContextPath()%>/saveorder.action?total="+total;
		for(var i=0;i<items.length;i++){
			server+="&details="+items[i].batch;
		}
		document.orderform.action=server;
		return true;
	}
}
function setTable(cook){
	total=0;
	if(cook==null)return;
	var cont='<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">';
	cont+='<tr><td height="27" align="center" class="xian_01">商品名称 </td>';
	cont+='<td height="27" align="center" class="xian_01">编号</td>';
	cont+='<td height="27" align="center" class="xian_01">证书</td>';
	cont+='<td height="27" align="center" class="xian_01">钻重</td>';
	cont+='<td height="27" align="center" class="xian_01">净度 </td>';
	cont+='<td height="27" align="center" class="xian_01">单价 </td>';
	cont+='<td height="27" align="center" class="xian_01">切工</td>';
	cont+='<td height="27" align="center" class="xian_01">操作</td></tr>';
	for(var i=0;i<cook.length;i++){
		cont+='<tr';
		if(i%2==0){cont+=' bgcolor="#2e2e2e"';}
		cont+='><td align="center" class="xian_02">&nbsp;'+cook[i].name+'</td>';
		cont+='<td align="center" class="xian_02">&nbsp;'+cook[i].batch+'</td>';
		cont+='<td align="center" class="xian_02">&nbsp;'+cook[i].lab+'</td>';
		cont+='<td align="center" class="xian_02">&nbsp;'+cook[i].weight+'</td>';
		cont+='<td align="center" class="xian_02">&nbsp;'+cook[i].clarity+'</td>';
		cont+='<td align="center" class="xian_02">￥'+cook[i].price+' </td>';
		cont+='<td align="center" class="xian_02">&nbsp;'+cook[i].finalCut+' </td>';
		cont+='<td align="center" class="xian_02"><a href="javascript:del('+i+')">删除</a></td></tr>';
		total+=parseInt(cook[i].price);
	}
	cont+='</table>';
	$("#datadiv").html(cont);
	$("#totalspan").html(total);
}
//-->
</script>
</head>

<body onload="MM_preloadImages('<%=request.getContextPath()%>/stage/images/menu0_01.jpg','<%=request.getContextPath()%>/stage/images/menu0_02.jpg','<%=request.getContextPath()%>/stage/images/menu0_03.jpg','<%=request.getContextPath()%>/stage/images/menu0_04.jpg','<%=request.getContextPath()%>/stage/images/menu0_05.jpg','<%=request.getContextPath()%>/stage/images/menu0_06.jpg','<%=request.getContextPath()%>/stage/images/menu0_07.jpg')">
<div class="mainbody">
<%@ include file="head1.jsp"%>
 <div class="intermediate">
    <h1>当前位置：首页&nbsp;&gt;&nbsp;<b><FONT COLOR="#FFCC66">添加订单</FONT></b></h1>
<%@ include file="left.jsp"%>
     <div class="right">
     	  <form name="orderform" onsubmit="return saveOrder()" method="post">
	      <h4><img src="<%=request.getContextPath()%>/stage/images/xdd/xdd_03.jpg" width="92" height="15" /></h4>
		  <div class="dhd">
		  <ul>
             <li>用户姓名：<input id="buyerName" name="clientOrderBo.buyerName" type="text" class="dhd_srk" maxlength="50"/></li>
			 <li>用户电话：<input id="buyerTel" name="clientOrderBo.buyerTel" type="text" class="dhd_srk" maxlength="50"/></li>
			 <li>送货地址：<input id="address" name="clientOrderBo.address" type="text" class="dhd_srk" maxlength="100"/></li>
			 <li>下单日期：<input id="orderDate" name="clientOrderBo.orderDate" readonly="true" type="text" class="dhd_srk" />
			  <img onclick="WdatePicker({el:'orderDate'})" src="<%=request.getContextPath()%>/stage/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle"></li>
			 <li>提货日期：<input id="receiveDate" name="clientOrderBo.receiveDate" value="<s:property value="clientOrderBo.receiveDate"/>" class="dhd_srk" readonly="true" type="text"/>
			 <img onclick="WdatePicker({el:'receiveDate'})" src="<%=request.getContextPath()%>/stage/js/My97DatePicker/skin/datePicker.gif" width="16" height="22" align="absmiddle">
			 </li>
		     <li><span style=" float:left;line-height:82px;">商品说明：</span>
		       <label>
		        <textarea id="orderRemark" name="clientOrderBo.orderRemark" class="dhd_srk1"></textarea>
		       </label>
		     </li>
		  </ul>
		  </div>
		  <h6>商品列表：总价:<label id="totalspan"></label>元</h6>
           <div class="dhd_bg" id="datadiv"></div>
	  <h6 style="margin-top:10px;text-align:right;">
	    <label>
	    <input type="image" src="<%=request.getContextPath()%>/stage/images/xdd/tjdd.gif" />
	    </label>
	  </h6>
	  </form>
    </div>
 </div>
 <%@ include file="foot.jsp"%>
</div>
</body>
</html>
